package top.jianx.demo.shiro.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description SwaggerConfig Swagger2的配置
 * @ClassName SwaggerConfig
 * @Author Jianx  <[email]jianx@jianx.top>
 * @date 2020.03.04
 */
@Configuration
@EnableSwagger2
@EnableWebMvc
public class SwaggerConfig {
    @Bean
    public Docket createApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("top.jianx.demo.shiro"))
                // 路径使用any风格
                .paths(PathSelectors.any())
                .build()
                // 如何保护我们的Api，有三种验证（ApiKey, BasicAuth, OAuth）
                //.securitySchemes(security())
                ;
    }

    /**
     * 接口文档详细信息
     *
     * @return
     */
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("springBoot 整合 Swagger2 实例")
                .description("更多技术内容分享见博客：https://jianx.top")
                .termsOfServiceUrl("https://jianx.top")
                .version("1.0")
                .build();
    }

    // 如何保护我们的Api，有三种验证（ApiKey, BasicAuth, OAuth）
    @Deprecated
    private List<ApiKey> security() {
        List<ApiKey> apiKeys = new ArrayList<>();
        apiKeys.add(new ApiKey("token", "token", "header"));
        return apiKeys;
    }
}
